package com.sgb.kjwl.view.ui.adapter.self.order;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.shopping.ShoppingCarResponse;
import com.swgk.core.util.UiUtil;
import com.swgk.core.util.StringUtil;

import java.math.BigDecimal;
import java.util.List;

/**
 * 描述：核对订单-商品2级适配器
 *
 * @author qiangHeNoo
 * <p>
 * 时间： 2021.04.27
 */
public class CheckChildOrderListAdapter extends BaseQuickAdapter<ShoppingCarResponse.ItemsData, BaseViewHolder> {


    public CheckChildOrderListAdapter(@Nullable List<ShoppingCarResponse.ItemsData> data) {
        super(R.layout.item_child_check_order, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final ShoppingCarResponse.ItemsData item) {
        String goodsPrice = "0.0";
        if (!TextUtils.isEmpty(String.valueOf(item.getPrice()))) {
            goodsPrice = StringUtil.showPrice(String.valueOf(item.getPrice()));
        }
        BigDecimal bd = BigDecimal.valueOf(item.getItemNum());
        bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);

        helper
                .setText(R.id.tv_product_name, item.getCartTitle())
                .setText(R.id.tv_price_value, "¥" + goodsPrice + "/" + item.getUnit())
                .setVisible(R.id.image_icon_vip, item.getChoosePriceType() == 3)
                .setText(R.id.tv_count, "X" + UiUtil.rvZeroAndDot(bd.toString()))
                .setVisible(R.id.sku_tag, item.getPromoteStatus() == 2 && item.getChoosePriceType() != 1);

        ImageView ivPhoto = helper.getView(R.id.iv_photo);
        Glide.with(UiUtil.getContext()).load(item.getImageUrls().get(0)).into(ivPhoto);
        switch (item.getPriceType()) {
            case 2:
                helper.setTextColor(R.id.tv_price_value, UiUtil.getColor(R.color.color_FF4B10));
                break;
            case 3:
                helper.setTextColor(R.id.tv_price_value, UiUtil.getColor(R.color.colorF7AB01));
                break;
            default:
                helper.setTextColor(R.id.tv_price_value, UiUtil.getColor(R.color.c_FF2928));
                break;
        }

        if (item.getShowCommoditySkuDetail() == null || "".equals(item.getShowCommoditySkuDetail())) {
            helper.setVisible(R.id.tv_material_specifications, false);
        } else {
            helper.setVisible(R.id.tv_material_specifications, true);
            helper.setText(R.id.tv_material_specifications, item.getShowCommoditySkuDetail());
        }
    }

}
